<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

/*	$query = $db_query = sprintf("SELECT a.agent_id, a.name_short, a.name_full
	FROM agent a
  		LEFT JOIN people p ON a.agent_id = p.agent_person_id
	WHERE p.is_signatory = 1 OR a.agent_id = 1");
	
	$items = mysql_query($query);	
*/

	$query = new Doctrine_Query();
    $query->from('Agent a')
    		->leftJoin('a.People p')
    			->where('p.is_signatory = 1 OR a.agent_id = 1')
    			->orderby('name_full, name_short');
                  
    $items = $query->execute();   
   
$dom = new DomDocument('1.0');
$dom->formatOutput = true;

$root = $dom->createElement( "results" );
$dom->appendChild( $root );
	//while(($item = mysql_fetch_assoc($items))){
	foreach ($items as $item){
		$dn = $dom->createElement( "record" );		
		$dn->setAttribute( 'data', $item['agent_id'] );
		$dn->setAttribute( 'label', utf8_encode($item['name_full'].', '.utf8_encode($item['name_short'])  ));
		$root->appendChild( $dn );		
}
header( "Content-type: text/xml");
echo $dom->saveXML();



?>